
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>库存告警设置</title>
	<link href="../../rs/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="../../rs/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
	<link href="../../rs/plugins/bootstrap_tab/css/bootstrap-table.css" rel="stylesheet">
	<link href="../../rs/css/animate.min.css" rel="stylesheet">
	<link href="../../rs/css/style.min862f.css?v=4.1.0" rel="stylesheet">
	<link href="../../rs/plugins/datapicker/datepicker3.css" rel="stylesheet">
	<link href="../../rs/plugins/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet">
  <?php
    require_once('login.php');
   ?>
  <style>
         #toolbar1 {
             padding: 0px 15px;
             float: right;
         }
         .btn-group-sm > .btn, .btn-sm {
             padding: 5px 12px;
         }

         .editable-click, a.editable-click, a.editable-click:hover {
             border-bottom: 0px;
         }
         .fixed-table-pagination .page-list{
             display: none;
         }
     </style>


</head>

<body class="gray-bg">
  <div class="wrapper wrapper-content animated fadeInRight">
      <div class="ibox float-e-margins">
          <div class="ibox-content">
              
              <div class="row">
                 <div class="col-sm-4 m-b-xs">
                    <div class="input-group ">
                        <span class="input-group-btn">
                            <button style="height:34px;background-color: #FFF;border: 1px solid #e5e6e7;font-size: 14px;margin-left:-1px" type="button" class="btn btn-sm ">仓库</button>
                        </span>
                            <select class="form-control" id="m_ck"></select>
                   </div>
               </div>
          <div class="col-sm-4 m-b-xs"></div>
          <div class="col-sm-4 m-b-xs">
          <div id="toolbar1">
              <button  onclick="search_do()" style="float:left;margin-left:5px" class="btn btn-info"  >
                  执行
              </button>
              <button onclick="save_do()" style="float:left;margin-left:5px" class="btn btn-success">
                  <i class="glyphicon glyphicon-ok"></i> 保存
              </button>
          </div>
        </div>
      </div>
              <table id="table"></table>
              <!-- End Example Card View -->
          </div>
      </div>
  </div>

<script src="../../rs/js/jquery.min.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/bootstrap-table.min.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="../../rs/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="../../rs/js/jquery.cookie.js"></script>
<script src="../../rs/js/common_qj.js"></script>
<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/plugins/bootstrap-editable/js/bootstrap-editable.js"></script>
<script src="../../rs/plugins/bootstrap-editable/js/bootstrap-table-editable.min.js"></script>
<script type="text/javascript">
     var $table = $('#table');
     var sign = URLencode($.cookie('sign'));
     $(function () {
         $('#table').bootstrapTable({
					 columns: [
 						 
 							{
 									field: 'prname1',
 									align: 'left',
 									title: '产品名称'
 							},
                             {
 									field: 'kc',
 									align: 'center', 
 									title: '库存数量'
 							},
                              {
 									field: 'prunit',
 									align: 'center', 
 									title: '单位'
 							},
 							
 							{
 									field: 'kcxx',
 									align: 'left',
 									title: '库存下限',
 									editable: true
 							} ,
                             {
 									field: 'kcsx',
 									align: 'left',
 									title: '库存上限',
 									editable: true,
 									 
 							}
 					],
                    advancedSearch: true,
                    idTable: "advancedTable",
                    shadeClose: true,
                    toggle: "table",
            //当修改数值后执行的保存操作
             onEditableSave: function (field, row, oldValue, $el) {
                 if (field == 'kcsx') {
                     if (isNaN(row.kcsx)) {
                         row.kcsx = oldValue;
                     }if(row.kcsx==""){
						row.kcsx = oldValue;
						 }else {
                      row.kcsx=parseFloat(row.kcsx).toFixed(2);
                     }
                 }
                 if (field == 'kcxx') {
                     if (isNaN(row.kcxx)) {
                         row.kcxx = oldValue;
                     }if(row.kcxx==""){
						row.kcxx = oldValue;
					 }else {
                         row.kcxx=parseFloat(row.kcxx).toFixed(2);
                     }
                 }
                 $('#table').bootstrapTable('load', getdata); 
             }
                });
                f_sheard();
                });
 

    //获取仓库 
     function f_sheard() {
         layer.load(2);
         //给仓库做循环
         $.ajax({
             type: "post",
             url:G_url+'sysg/see',
             data: 'sign=' + sign,
             dataType: "json",
             success: function (result) {
                 layer.closeAll('loading');
                 var ff = result.data;
                 var html1 = '';
                 $.each(ff, function (a, b) {//直接取出json的prolist做each循环.
                     html1 += "<option value='" + b.ShopGroupID + "'>" + b.ShopGroupName + "</option>";//拼接字符串.
                 });
                 $("#m_ck").append(html1);
                 //$("#mdbh1").append(html1);
             },
             error: function (XMLHttpRequest, textStatus, errorThrown) {
             }
         }); 
        
     }


   var getdata;
   function search_do(){
           //查询数据
           var ckbh=$("#m_ck option:selected").val();
           layer.msg('数据查询中...', {icon: 16, time: 200000, shade: [0.1, 'black']});
            $.ajax({
             type: "post",
             url:G_url+'stino/seeslpr/'+ckbh,
             data: 'sign=' + sign,
             dataType: "json",
             success: function (result) {
                 getdata=result.data;
                $('#table').bootstrapTable('load', result.data);
                layer.closeAll();
             },
             error: function (XMLHttpRequest, textStatus, errorThrown) {
             }
         }); 
   }

    //保存
    function save_do(){
         var ckbh=$("#m_ck option:selected").val();
             layer.confirm('确定要保存吗？', {
                 title: [''],
                 btn: ['确定', '取消'] //按钮
             }, function (index) {
                 layer.msg('数据保存中...', {icon: 16, time: 200000, shade: [0.1, 'black']});
                 
                    var data1=$('#table').bootstrapTable('getData');
                    var kk=[];
                    $.each(data1, function(idx, obj) {
                        var mm={"prid":obj.prid,"kcsx":obj.kcsx,"kcxx":obj.kcxx,"prname1":obj.prname1};
                        kk.push(mm);
                    });  
                    
                 var save={};
                 save.ckbh=ckbh;
                 save.detail=kk;
                  
                 $.ajax({
                     type: "post",
                     url: G_url+'stst/save_kcbj'+"?sign="+sign,
                     data:JSON.stringify(save),
                     dataType: "json",
                     success: function(res) {
                         if (res.ok){
                             layer.msg(res.msg); 
                         } else {
                             layer.msg(res.msg);
                         }
                     },
                     error: function (XMLHttpRequest, textStatus, errorThrown) {
                         layer.msg('数据保存失败', {time: 1000});
                     }
                 });
                 layer.close(index);
             }, function (index) {
                 layer.close(index);
             });

     }


         $("#m_ck").change(function () {
           var ckbh=$("#m_ck option:selected").val();
           layer.msg('数据查询中...', {icon: 16, time: 200000, shade: [0.1, 'black']});
            $.ajax({
             type: "post",
             url:G_url+'stino/seeslpr/'+ckbh,
             data: 'sign=' + sign,
             dataType: "json",
             success: function (result) {
                 getdata=result.data;
                
                $('#table').bootstrapTable('load', result.data);
                 layer.closeAll();
             },
             error: function (XMLHttpRequest, textStatus, errorThrown) {
             }
         }); 
		});
 </script>
</body>
</html>
